######################
# RUN THE OLS MODELS #
######################
# Author: Kasia Nalewajko
# First created: 7 November 2021
# Replicated: 8 June 2024

rm(list = ls())

# LOAD PACKAGES -----------------------------------------------------------

if (!require("dplyr")) install.packages("dplyr")
if (!require("estimatr")) install.packages("estimatr")
if (!require("modelsummary")) install.packages("modelsummary")

# LOAD DATA ---------------------------------------------------------------

load("./00 SUBMITTED/00 APSR final/04 replication_files/01 data/main.Rda")

# RUN MODELS --------------------------------------------------------------

# Models 1 and 2: Logged count of Holocaust victims as DV
olsmin_count <- lm_robust(formula = log(all_jewish_victims+1) ~ log((FFIFFCgentile*1000/pop1936)+1)  + log(pop1936+1) + synagogues_dummy + log(collabos_antijew1000+1) + log(DHI_milipol_sum1942+1) 
                          + area_sqkm  + longitude + longitudesq + latitude + latitudesq + zone5,
                          clusters = resregion2,
                          fixed_effects = as.factor(ar_name),
                          data = main)

olsfull_count <- lm_robust(formula = log(all_jewish_victims+1) ~ log((FFIFFCgentile*1000/pop1936)+1) + log(pop1936+1) + synagogues_dummy + log(collabos_antijew1000+1) + log(DHI_milipol_sum1942+1) 
                           + area_sqkm  + longitude + longitudesq + latitude + latitudesq + zone5
                           + log(FRANCISTE_36_1_pct+1) + log(ActionFrancaise_19_pct+1) + log(nuance_extremedroite_36_1_pct+1) + catholic_churches + turnout_36_1_pct  + log(nuance_centredroit_36_1_pct+1) + log(nuance_droite_36_1_pct+1) + log(nuance_centregauche_36_1_pct+1) + log(nuance_gauche_36_1_pct+1) + log(nuance_extremegauche_36_1_pct+1),
                           clusters = resregion2,
                           fixed_effects = as.factor(ar_name),
                           data = main)


# Models 3 and 4: Logged proportion of Holocaust victims as DV

olsmin_prop <- lm_robust(formula = log(((all_jewish_victims+1)/(allocated_jpop+1)+1)) ~ log((FFIFFCgentile*1000/pop1936)+1)  + log(allocated_jpop+1)  + log(pop1936+1) + synagogues_dummy + log(collabos_antijew1000+1) + log(DHI_milipol_sum1942+1) 
                         + area_sqkm  + longitude + longitudesq + latitude + latitudesq + zone5,
                         clusters = resregion2,
                         fixed_effects = as.factor(ar_name),
                         data = main)

olsfull_prop <- lm_robust(formula = log(((all_jewish_victims+1)/(allocated_jpop+1)+1)) ~ log((FFIFFCgentile*1000/pop1936)+1) + log(allocated_jpop+1)  + log(pop1936+1) + synagogues_dummy + log(collabos_antijew1000+1) + log(DHI_milipol_sum1942+1) 
                          + area_sqkm  + longitude + longitudesq + latitude + latitudesq + zone5
                          + log(FRANCISTE_36_1_pct+1) + log(ActionFrancaise_19_pct+1) + log(nuance_extremedroite_36_1_pct+1) + catholic_churches + turnout_36_1_pct  + log(nuance_centredroit_36_1_pct+1) + log(nuance_droite_36_1_pct+1) + log(nuance_centregauche_36_1_pct+1) + log(nuance_gauche_36_1_pct+1) + log(nuance_extremegauche_36_1_pct+1),
                          clusters = resregion2,
                          fixed_effects = as.factor(ar_name),
                          data = main)

modelsummary(list(olsmin_count, olsfull_count, olsmin_prop, olsfull_prop),
             stars = c('*' = .1, '**' = .05, '***' = .01))

# OUTPUT TO LATEX ---------------------------------------------------------------

modelsummary(list(olsmin_count, olsfull_count, olsmin_prop, olsfull_prop),
             stars = c('*' = .1, '**' = .05, '***' = .01),
             output = "latex",
             gof_omit = "AIC|BIC|RMSE|R2 Within|R2 Within Adj.",
             coef_omit = "zone5",
             title = "OLS results",
             coef_rename = c("log((FFIFFCgentile * 1000/pop1936) + 1)" = "Insurgent presence",
                             "log(pop1936 + 1)" = "1936 population",
                             "log(collabos_antijew1000 + 1)" = "Collaborators",
                             "log(DHI_milipol_sum1942 + 1)" = "1942 state presence",
                             "synagogues_dummy" = "Synagogues",
                             "area_sqkm" = "Area size (km2)",
                             "longitude" = "Longitude",
                             "latitude" = "Latitude",
                             "longitudesq" = "Longitude (sq)",
                             "latitudesq" = "Latitude (sq)",
                             "log(allocated_jpop + 1)" = "1941 Jewish population",
                             "catholic_churches" = "Catholic churches",
                             "log(FRANCISTE_36_1_pct + 1)" = "Franciste vote 1936",
                             "log(ActionFrancaise_19_pct + 1)" = "Action Française vote 1919",
                             "turnout_36_1_pct" = "Turnout 1936",
                             "log(nuance_droite_36_1_pct + 1)" = "Right vote 1936",
                             "log(nuance_centredroit_36_1_pct + 1)" = "Centre-right vote 1936",
                             "log(nuance_centregauche_36_1_pct + 1)" = "Centre-left vote 1936",
                             "log(nuance_gauche_36_1_pct + 1)" = "Left vote 1936",
                             "log(nuance_extremegauche_36_1_pct + 1)" = "Extreme left vote 1936"
             ))




